package com.hulk.dryad.common.util;

import cn.hutool.crypto.digest.DigestUtil;
import lombok.extern.slf4j.Slf4j;

import java.nio.charset.StandardCharsets;

/**
 * @author lqx
 */
@Slf4j
public class Sha256Util {

    /**
     * 签名
     * @param signStr 签名字符串
     * @return 签名结果字符串
     */
    public static String sign(String signStr){
        return DigestUtil.sha256Hex(signStr.getBytes(StandardCharsets.UTF_8));
    }


    /**
     * 签名验证
     * @param verifyStr 验证字符串
     * @param sign 签名值
     * @return 对比字符串
     */
    public static boolean verify(String verifyStr,String sign){
        String singnStr = DigestUtil.sha256Hex(verifyStr.getBytes(StandardCharsets.UTF_8));
        return sign.equals(singnStr);
    }
}
